package com.ht.util;

import lombok.val;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @ProjectName: ht_screen
 * @ClassName: FileUtil
 * @Author: hejialun
 * @Description: 文件工具类
 * @Date: 2021/8/11 10:22
 */
public class FileUtil {


    /**
     * 获取文件大小-保留两位小数
     *
     * @param size:文件k
     * @param type:转化（KB/M/G）
     * @return
     */
    public static BigDecimal getFileSize(Long size, String type) {
        BigDecimal bigDecimal = new BigDecimal(0);
        Integer val=1;
        switch (type) {
            case "KB":
                val = 1024;
                break;
            case "M":
                val = 1024 * 1024;
                break;
            case "G":
                val = 1024 * 1024 * 1024;
                break;
        }
        bigDecimal = new BigDecimal(size.toString()).divide(new BigDecimal(val.toString()), 2, BigDecimal.ROUND_HALF_UP);
        return bigDecimal;


    }
}